#!/bin/bash
#

nginx=/usr/local/nginx/sbin/nginx
nginx_pid=/usr/local/nginx/logs/nginx.pid

#判断脚本是否有参数
if [ -z $1 ]; then
    echo "help: $0 <start|stop|restart|status|reload>"
    exit 81
fi

case $1 in
  start)
    $nginx
    if [ $? -eq 0 ]; then
        echo "nginx启动成功"
    else
        echo "nginx启动失败"
    fi
    ;;
  stop)
    $nginx -s stop
    ;;
  restart)
    $nginx -s stop
    sleep 1
    $nginx
    ;;
  status)
    if [ -f $nginx_pid ]; then
        echo "nginx(PID $(cat $nginx_pid)) is running"
    else
        echo "nginx is stopped"
    fi
    ;;
  reload)
    KILL -HUP $(cat $nginx_pid)
    ;;
  *)
    echo "help: $0 <start|stop|restart|status|reload>"
esac
